package com.trg.flex.remote
{
	import com.trg.flex.FlexUtils;
	
	public class Queue
	{
		public var id:String;
		public var waiting:Array = [];
		public var outstanding:Array = [];
		public var all:Array = [];
		
		public function removeFromWaiting(call:RemoteCall):void {
			var pos:int = FlexUtils.indexOf(waiting, call);
			if (pos != -1)
				waiting.splice(pos, 1);
		}
		
		public function removeFromOutstanding(call:RemoteCall):void {
			var pos:int = FlexUtils.indexOf(outstanding, call);
			if (pos != -1)
				outstanding.splice(pos, 1);
		}
		
		public function toString():String {
			var s:String = "<Queue " + id + ">\n";
			var c:RemoteCall;
			for each (c in waiting)
				s += c.description + "\n";
			s += " -------- \n";
			for each (c in outstanding)
				s += c.description + "\n";
			s += " -------- \n";
			for each (c in all)
				s += c.description + "\n";
			s += "</Queue>\n";
			return s;
		}
	}
}